<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:replace="~{/_include/header}" />
    <meta name="page-help" content="https://getrebuild.com/docs/admin/meta-entity" />
    <title>[[${bundle.L('AdvConf')}]]</title>
    <style type="text/css">
      a#entityIcon {
        display: inline-block;
        width: 36px;
        height: 36px;
        background-color: #e3e3e3;
        text-align: center;
        border-radius: 2px;
      }
      a#entityIcon .icon {
        font-size: 26px;
        color: #555;
        line-height: 36px;
      }
      a#entityIcon:hover {
        opacity: 0.8;
      }
    </style>
  </head>
  <body>
    <div class="rb-wrapper rb-fixed-sidebar rb-collapsible-sidebar rb-collapsible-sidebar-hide-logo rb-aside rb-color-header" th:classappend="${sideCollapsedClazz}">
      <th:block th:replace="~{/_include/nav-top}" />
      <th:block th:replace="~{/_include/nav-left-admin(active='entities')}" />
      <div class="rb-content">
        <aside class="page-aside">
          <div class="rb-scroller-aside rb-scroller">
            <div class="aside-content">
              <div class="content">
                <div class="aside-header">
                  <button class="navbar-toggle collapsed" type="button"><span class="icon zmdi zmdi-caret-down"></span></button>
                  <span class="title">[[${entityLabel}]]</span>
                  <p class="description">[[${comments}]]</p>
                </div>
              </div>
              <div class="aside-nav collapse">
                <ul class="nav">
                  <li><a href="base">[[${bundle.L('BasicInfo')}]]</a></li>
                  <li><a href="fields">[[${bundle.L('NavFields')}]]</a></li>
                  <li><a href="form-design">[[${bundle.L('FormLayout')}]]</a></li>
                  <li class="active"><a href="advanced">[[${bundle.L('AdvConf')}]]</a></li>
                </ul>
              </div>
            </div>
          </div>
        </aside>
        <div class="page-head">
          <div class="page-head-title">[[${bundle.L('AdvConf')}]]</div>
        </div>
        <div class="main-content container-fluid pt-1">
          <div class="card">
            <div class="card-header">[[${bundle.L('DeleteSome,Entity')}]]</div>
            <div class="card-body">
              <p th:utext="${bundle.L('DeleteEntityTips')}"></p>
              <div>
                <label class="custom-control custom-control-sm custom-checkbox custom-control-inline mb-2">
                  <input class="custom-control-input J_drop-check" type="checkbox" /><span class="custom-control-label"> [[${bundle.L('IKnowRisks')}]]</span>
                </label>
                <label class="custom-control custom-control-sm custom-checkbox custom-control-inline mb-2 bosskey-show">
                  <input class="custom-control-input J_drop-force" type="checkbox" /><span class="custom-control-label"> [[${bundle.L('ForceDelete')}]]</span>
                </label>
              </div>
              <div class="mb-1">
                <button type="button" class="btn btn-danger J_drop-confirm" disabled="disabled"><i class="zmdi zmdi-delete icon"></i> [[${bundle.L('Confirm')}]]</button>
                <div class="alert alert-warning alert-icon hide col-sm-6 mb-0">
                  <div class="icon"><span class="zmdi zmdi-alert-triangle"></span></div>
                  <div class="message">[[${bundle.L('BuiltInNotDelete')}]]</div>
                </div>
              </div>
            </div>
          </div>
          <div class="card bosskey-show">
            <div class="card-header">[[${bundle.L('ExportSome,Entity')}]]</div>
            <div class="card-body">
              <p class="link" th:utext="${bundle.L('ExportEntityTips')}"></p>
              <div class="mb-1">
                <a th:href="|../entity-export?id=${entityMetaId}|" target="_blank" class="btn btn-primary"><i class="zmdi zmdi-cloud-download icon"></i> [[${bundle.L('Export')}]]</a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <th:block th:replace="~{/_include/footer}" />
    <script>
      window.__PageConfig = {
        id: '[[${entityMetaId}]]',
        isSuperAdmin: '[[${isSuperAdmin}]]' === 'true',
      }
    </script>
    <script type="text/babel">
      $(document).ready(function () {
        const metaId = window.__PageConfig.id
        if (!!!metaId) {
          $('.J_drop-confirm').next().removeClass('hide')
          $('.J_drop-confirm').remove()
          $('.J_drop-check').parent().parent().remove()
          return
        }

        $('.J_drop-check').click(function () {
          $('.J_drop-confirm').attr('disabled', $(this).prop('checked') == false)
        })

        const $drop = $('.J_drop-confirm').click(() => {
          if ($('.J_drop-check').prop('checked') == false) return
          if (!window.__PageConfig.isSuperAdmin) {
            RbHighbar.error($L('OnlyAdminCanSome,DeleteEntity'))
            return
          }

          RbAlert.create($L('DeleteEntityConfirm'), $L('DeleteEntity'), {
            type: 'danger',
            confirmText: $L('Delete'),
            confirm: function () {
              $drop.button('loading')
              this.disabled(true)
              $.post('../entity-drop?id=' + metaId + '&force=' + $('.J_drop-force').prop('checked'), (res) => {
                if (res.error_code == 0) {
                  RbHighbar.success($L('SomeDeleted,Entity'))
                  setTimeout(function () {
                    location.replace('../../entities')
                  }, 1500)
                } else {
                  RbHighbar.error(res.error_msg)
                }
              })
            },
            call: function () {
              $countdownButton($(this._dlg).find('.btn-danger'))
            },
          })
        })
      })
    </script>
  </body>
</html>
